﻿namespace UnityEditor
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Text.RegularExpressions;
    using UnityEditorInternal;
    using UnityEngine;

    internal class PostProcessiPhonePlayer
    {
        private const string iPadIcon = "Icon-72.png";
        private const string iPadIcon2x = "Icon-144.png";
        private const string iPhonePlugins = "Assets/Plugins/iOS";
        private const string iPhoneTallSplash = "Default-568h@2x.png";
        private static string[] kiOSSDKVersions = new string[] { 
            "iphoneos2.0", "iphoneos2.1", "iphoneos2.2", "iphoneos2.2.1", "iphoneos3.0", "iphoneos3.1", "iphoneos3.1.2", "iphoneos3.1.3", "iphoneos3.2", "iphonesimulator3.2", "iphoneos4.0", "iphonesimulator4.0", "iphoneos4.1", "iphonesimulator4.1", "iphoneos4.2", "iphonesimulator4.2", 
            "iphoneos4.3", "iphonesimulator4.3", "iphoneos5.0", "iphonesimulator5.0", "iphoneos5.1", "iphonesimulator5.1", "iphoneos6.0", "iphonesimulator6.0"
         };
        private const string kLatestDeviceSDKValue = "iphoneos";
        private const string kLatestSimulatorSDKValue = "iphonesimulator";
        private static string[] kReservedFilenames = new string[] { "AppController.h", "AppController.mm", "MainWindow.xib", "RegisterClasses.cpp", "RegisterClasses.h", "iPhone_target2AppDelegate.h", "iPhone_target2AppDelegate.m", "main.mm", "iPhone_Common.h", "iPhone_Profiler.h", "iPhone_Profiler.cpp", "iPhone_GlesSupport.h", "iPhone_GlesSupport.cpp", "iPhone_View.h", "iPhone_View.mm" };
        private static string kXcodePluginDestination = (Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin");
        private const string kXcodePluginName = "Unity4XC.xcplugin";

        private static void AddiPhoneAssemblyFiles(List<string> includedFiles, string[] filesToAdd)
        {
            foreach (string str in filesToAdd)
            {
                if ((str != null) && str.EndsWith(".dll"))
                {
                    includedFiles.Add("Libraries/" + str + ".s");
                }
            }
        }

        private static void AddiPhonePluginFiles(List<string> includedFiles)
        {
            if (Directory.Exists("Assets/Plugins/iOS"))
            {
                foreach (string str in Directory.GetFiles("Assets/Plugins/iOS"))
                {
                    if (IsiPhonePluginFile(str))
                    {
                        includedFiles.Add("Libraries/" + Path.GetFileName(str));
                    }
                }
            }
        }

        private static void AddStandardImages(List<string> includedFiles)
        {
            includedFiles.Add("Icon@2x.png");
            if (IsIPhoneEnabled())
            {
                includedFiles.Add("Default@2x.png");
                includedFiles.Add("Default-568h@2x.png");
            }
            if (IsIPadEnabled())
            {
                includedFiles.Add("Default-Landscape.png");
                includedFiles.Add("Default-Portrait.png");
                includedFiles.Add("Default-Landscape@2x.png");
                includedFiles.Add("Default-Portrait@2x.png");
            }
            if (IsIPhoneEnabled() && IsIPadEnabled())
            {
                includedFiles.Add("Icon-72.png");
                includedFiles.Add("Icon-144.png");
            }
        }

        private static void BuildXCodeProject(string pbxprojFile, List<string> fileNames, string sdkVersion, string targetOS, bool appendMode)
        {
            if (fileNames.Count > 0xff)
            {
                throw new System.Exception("More than 256 script dll's is currently not supported.");
            }
            ArrayList list = FileUtil.ReadAllText(pbxprojFile);
            ArrayList xcodeXMLFileContentOut = new ArrayList();
            Regex regex = new Regex("D8A1C70..E80637F.00160D4");
            Regex regex2 = new Regex("567B620..14A9F340000AA1F");
            Regex regex3 = new Regex("(?<first>D8A1C70)(..)(?<second>E80637F000160D4)");
            Regex regex4 = new Regex("(?<first>D8A1C70)(..)(?<second>E80637F100160D4)");
            string str = "D8A1C72A0E8063A1000160D3";
            string str2 = "567B635B114AA8010000AA1F";
            string str3 = "D8A1C72B0E8063A1000160D3";
            string[] addValues = new string[] { !IsSimulatorSDK(sdkVersion) ? "-mno-thumb" : "-DTARGET_IPHONE_SIMULATOR=1" };
            string[] removeValues = new string[] { IsSimulatorSDK(sdkVersion) ? "-mno-thumb" : "-DTARGET_IPHONE_SIMULATOR=1" };
            IEnumerator it = list.GetEnumerator();
            while (it.MoveNext())
            {
                string current = (string) it.Current;
                if ((current.IndexOf("mscorlib.dll.s") != -1) && !regex2.Match(current).Success)
                {
                    if (!regex.Match(current).Success)
                    {
                        throw new System.Exception("Append is not supported for old version of XCode project. Build your project to different location or replace existing one.");
                    }
                    for (int i = 0; i < fileNames.Count; i++)
                    {
                        if (!fileNames[i].EndsWith(".a") && !isReservedFile(fileNames[i]))
                        {
                            string path = fileNames[i];
                            string input = current;
                            string escapedName = GetEscapedName(Path.GetFileName(path));
                            string str8 = GetEscapedName(path);
                            input = input.Replace("name = mscorlib.dll.s", "name = " + escapedName).Replace("path = Libraries/mscorlib.dll.s", "path = " + str8).Replace("lastKnownFileType = sourcecode.asm", "lastKnownFileType = " + ResolveXcodeFiletypeFromName(path)).Replace("mscorlib.dll.s", Path.GetFileName(path));
                            input = regex3.Replace(input, "${first}" + string.Format("{0:x2}", i) + "${second}");
                            input = regex4.Replace(input, "${first}" + string.Format("{0:x2}", i) + "${second}");
                            xcodeXMLFileContentOut.Add(input);
                        }
                    }
                }
                else
                {
                    if ((current.Contains(str) || current.Contains(str2)) || current.Contains(str3))
                    {
                        for (int j = 0; j < fileNames.Count; j++)
                        {
                            if (fileNames[j].EndsWith(".a") && !isReservedFile(fileNames[j]))
                            {
                                string newValue = string.Format("D8A1C70{0:x2}E80637F100160D4", j);
                                string str10 = string.Format("D8A1C70{0:x2}E80637F000160D4", j);
                                string str11 = string.Format("D8A1C70{0:x2}E80637F200160D4", j);
                                string str12 = GetEscapedName(Path.GetFileName(fileNames[j]));
                                string str13 = current;
                                str13 = str13.Replace(str, newValue).Replace(str2, str10).Replace(str3, str11).Replace("libiPhone-lib.a", str12);
                                xcodeXMLFileContentOut.Add(str13);
                            }
                        }
                        xcodeXMLFileContentOut.Add(current);
                        continue;
                    }
                    if (((((!ReplaceMultilinePropertyIfMatch(it, "ARCHS", GetTargetArchitecture(sdkVersion), xcodeXMLFileContentOut) && !ReplacePropertyLineIfMatch((string) it.Current, "TARGETED_DEVICE_FAMILY", GetTargetDeviceFamily(PlayerSettings.iOS.targetDevice), xcodeXMLFileContentOut)) && !UpdateMultilinePropertyIfMatch(it, "OTHER_CFLAGS", addValues, removeValues, xcodeXMLFileContentOut)) && ((sdkVersion.Length <= 0) || !ReplacePropertyLineIfMatch((string) it.Current, "SDKROOT", sdkVersion, xcodeXMLFileContentOut))) && ((sdkVersion.Length <= 0) || !ReplacePropertyLineIfMatch((string) it.Current, "SUPPORTED_PLATFORMS", sdkVersion, xcodeXMLFileContentOut))) && (((sdkVersion.Length <= 0) || !ReplacePropertyLineIfMatch((string) it.Current, "IPHONEOS_DEPLOYMENT_TARGET", GetSDKNumber(targetOS), xcodeXMLFileContentOut)) && (!appendMode || !regex.Match((string) it.Current).Success)))
                    {
                        xcodeXMLFileContentOut.Add(it.Current);
                    }
                }
            }
            FileUtil.WriteAllText(pbxprojFile, xcodeXMLFileContentOut);
        }

        public static void CloseUnityProjectsInXcode()
        {
            if (useXcode4)
            {
                CloseUnityProjectsInXcode4();
            }
            else
            {
                CloseUnityProjectsInXcode3();
            }
        }

        public static void CloseUnityProjectsInXcode3()
        {
            if (XcodeIsRunning())
            {
                string str = "\n\t\ttell application \"Xcode\"\n\tactivate\n\tset unity_windows to (every window whose (name is \"Unity-iPhone\") and (visible is true))\n\trepeat with win in unity_windows\n\t\tshow win\n\t\tset projectSelection to (call method \"projectSelection\" of class \"XCActionManager\")\n\t\tif projectSelection is not null then\n\t\t\tcall method \"stopDebugAndRunSessions\" of projectSelection\n\t\tend if\n\t\tclose win\n\tend repeat\nend tell";
                string[] script = new string[] { str };
                LaunchOsascript(script, true);
            }
        }

        public static void CloseUnityProjectsInXcode4()
        {
            Unsupported.LaunchIPhoneXCode4();
            try
            {
                Xcode4Controller.CloseAllOpenUnityProjects();
            }
            catch (System.Exception exception)
            {
                object[] param = new object[] { exception };
                Xcode4Controller.Log("Close all open unity project in Xcode failed. {0}", param);
            }
        }

        private static void CopyLandscapeLIPhoneSplash(string editorTrampolineFolder, string installPath)
        {
            string to = installPath + "/Default.png";
            string str2 = installPath + "/Default@2x.png";
            string str3 = installPath + "/Default-568h@2x.png";
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-LandscapeL.png", to);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-LandscapeL@2x.png", str2);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-Landscape-568h-L@2x.png", str3);
        }

        private static void CopyLandscapeRIPhoneSplash(string editorTrampolineFolder, string installPath)
        {
            string to = installPath + "/Default.png";
            string str2 = installPath + "/Default@2x.png";
            string str3 = installPath + "/Default-568h@2x.png";
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-LandscapeR.png", to);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-LandscapeR@2x.png", str2);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-Landscape-568h-R@2x.png", str3);
        }

        private static void CopyPortraitIPhoneSplash(string editorTrampolineFolder, string installPath)
        {
            string to = installPath + "/Default.png";
            string str2 = installPath + "/Default@2x.png";
            string str3 = installPath + "/Default-568h@2x.png";
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-Portrait.png", to);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-Portrait@2x.png", str2);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-Portrait-568h@2x.png", str3);
        }

        private static void CopyPortraitUIPhoneSplash(string editorTrampolineFolder, string installPath)
        {
            string to = installPath + "/Default.png";
            string str2 = installPath + "/Default@2x.png";
            string str3 = installPath + "/Default-568h@2x.png";
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-PortraitU.png", to);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-PortraitU@2x.png", str2);
            FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/SplashScreen-Portrait-568h-U@2x.png", str3);
        }

        private static void CopyRecursiveWithIgnoreList(string src, string dst, Regex[] ignoreList)
        {
            if (!MatchesAny(Path.GetFileName(src), ignoreList))
            {
                if (File.Exists(src))
                {
                    FileUtil.CopyFileOrDirectory(src, dst);
                }
                else
                {
                    Directory.CreateDirectory(dst);
                    foreach (string str in Directory.GetDirectories(src))
                    {
                        CopyRecursiveWithIgnoreList(str, Path.Combine(dst, Path.GetFileName(str)), ignoreList);
                    }
                    foreach (string str2 in Directory.GetFiles(src))
                    {
                        CopyRecursiveWithIgnoreList(str2, Path.Combine(dst, Path.GetFileName(str2)), ignoreList);
                    }
                }
            }
        }

        private static void CreateDirectory(DirectoryInfo dirInfo)
        {
            if (dirInfo.Parent != null)
            {
                CreateDirectory(dirInfo.Parent);
            }
            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
        }

        private static void DeleteNonHiddenFilesOrDirectories(string item)
        {
            if ((item != null) && !Path.GetFileName(item).StartsWith("."))
            {
                if (File.Exists(item))
                {
                    File.Delete(item);
                }
                else
                {
                    foreach (string str in Directory.GetDirectories(item))
                    {
                        if (!Path.GetFileName(str).StartsWith("."))
                        {
                            DeleteNonHiddenFilesOrDirectories(str);
                        }
                    }
                    foreach (string str2 in Directory.GetFiles(item))
                    {
                        if (!Path.GetFileName(str2).StartsWith("."))
                        {
                            FileUtil.DeleteFileOrDirectory(str2);
                        }
                    }
                    if ((Directory.GetFiles(item).Length == 0) && (Directory.GetDirectories(item).Length == 0))
                    {
                        Directory.Delete(item);
                    }
                }
            }
        }

        private static string ExtractValue(string expr)
        {
            if (expr == null)
            {
                return null;
            }
            int length = expr.LastIndexOf(",");
            if (length != -1)
            {
                expr = expr.Substring(0, length).Trim();
                char[] trimChars = new char[] { '"' };
                char[] chArray2 = new char[] { '"' };
                expr = expr.TrimStart(trimChars).TrimEnd(chArray2);
            }
            return expr;
        }

        private static string GetEscapedName(string name)
        {
            if (name.IndexOfAny(" @+".ToCharArray()) != -1)
            {
                return ("\"" + name + "\"");
            }
            return name;
        }

        private static string GetSDKNumber(string sdkVersion)
        {
            for (int i = 0; i < sdkVersion.Length; i++)
            {
                if ((sdkVersion[i] >= '0') && (sdkVersion[i] <= '9'))
                {
                    return sdkVersion.Substring(i);
                }
            }
            return "4.0";
        }

        private static string GetTargetArchitecture(string sdkName)
        {
            if (IsSimulatorSDK(sdkName))
            {
                return "i386";
            }
            return "armv7";
        }

        private static string GetTargetDeviceFamily(iOSTargetDevice targetDevice)
        {
            if (targetDevice == iOSTargetDevice.iPhoneOnly)
            {
                return "\"1\"";
            }
            if (targetDevice == iOSTargetDevice.iPadOnly)
            {
                return "\"2\"";
            }
            return "\"1,2\"";
        }

        private static string GetXcodeUserProjectFile()
        {
            return ("Unity-iPhone.xcodeproj/" + Environment.GetEnvironmentVariable("USER") + ".pbxuser");
        }

        private static void InstalliPadIcons(string editorTrampolineFolder, string tempData, string stagingArea, string installPath, bool appendMode)
        {
            string path = installPath + "/Default.png";
            string str2 = installPath + "/Default-Landscape.png";
            string str3 = installPath + "/Default-Portrait.png";
            string str4 = installPath + "/Default-Landscape@2x.png";
            string str5 = installPath + "/Default-Portrait@2x.png";
            if (!PlayerSettings.advancedLicense)
            {
                if (IsIPadEnabled() && !IsIPhoneEnabled())
                {
                    FileUtil.DeleteFileOrDirectory(path);
                    if ((PlayerSettings.defaultInterfaceOrientation == UIOrientation.Portrait) || (PlayerSettings.defaultInterfaceOrientation == UIOrientation.PortraitUpsideDown))
                    {
                        FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/Default-Portrait.png", path);
                    }
                    else
                    {
                        FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/Default-Landscape.png", path);
                    }
                }
                FileUtil.DeleteFileOrDirectory(str2);
                FileUtil.DeleteFileOrDirectory(str4);
                FileUtil.DeleteFileOrDirectory(str3);
                FileUtil.DeleteFileOrDirectory(str5);
                FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/Default-Landscape.png", str2);
                FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/Default-Landscape@2x.png", str4);
                FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/Default-Portrait.png", str3);
                FileUtil.CopyFileOrDirectory(editorTrampolineFolder + "/Default-Portrait@2x.png", str5);
                File.SetLastWriteTime(str2, DateTime.Now);
                File.SetLastWriteTime(str3, DateTime.Now);
            }
            else
            {
                FileUtil.MoveFileIfExists(stagingArea + "/Default-Landscape.png", installPath + "/Default-Landscape.png");
                FileUtil.MoveFileIfExists(stagingArea + "/Default-Landscape@2x.png", installPath + "/Default-Landscape@2x.png");
                FileUtil.MoveFileIfExists(stagingArea + "/Default-Portrait.png", installPath + "/Default-Portrait.png");
                FileUtil.MoveFileIfExists(stagingArea + "/Default-Portrait@2x.png", installPath + "/Default-Portrait@2x.png");
            }
            if (IsIPadEnabled() && !IsIPhoneEnabled())
            {
                FileUtil.MoveFileIfExists(stagingArea + "/Icon-72.png", installPath + "/Icon.png");
                FileUtil.MoveFileIfExists(stagingArea + "/Icon-144.png", installPath + "/Icon@2x.png");
            }
            else
            {
                FileUtil.MoveFileIfExists(stagingArea + "/Icon-72.png", installPath + "/Icon-72.png");
                FileUtil.MoveFileIfExists(stagingArea + "/Icon-144.png", installPath + "/Icon-144.png");
            }
        }

        private static void InstalliPhoneIcons(string editorTrampolineFolder, string tempData, string stagingArea, string installPath, bool appendMode)
        {
            string dst = installPath + "/Default.png";
            string str2 = installPath + "/Default@2x.png";
            string str3 = installPath + "/Default-568h@2x.png";
            if (PlayerSettings.advancedLicense)
            {
                FileUtil.MoveFileIfExists(stagingArea + "/Default.png", dst);
                FileUtil.MoveFileIfExists(stagingArea + "/Default@2x.png", str2);
                FileUtil.MoveFileIfExists(stagingArea + "/Default-568h@2x.png", str3);
            }
            else
            {
                FileUtil.DeleteFileOrDirectory(dst);
                FileUtil.DeleteFileOrDirectory(str2);
                FileUtil.DeleteFileOrDirectory(str3);
                switch (PlayerSettings.defaultInterfaceOrientation)
                {
                    case UIOrientation.Portrait:
                        CopyPortraitIPhoneSplash(editorTrampolineFolder, installPath);
                        break;

                    case UIOrientation.PortraitUpsideDown:
                        CopyPortraitUIPhoneSplash(editorTrampolineFolder, installPath);
                        break;

                    case UIOrientation.LandscapeRight:
                        CopyLandscapeRIPhoneSplash(editorTrampolineFolder, installPath);
                        break;

                    case UIOrientation.LandscapeLeft:
                        CopyLandscapeLIPhoneSplash(editorTrampolineFolder, installPath);
                        break;

                    case UIOrientation.AutoRotation:
                        if (!PlayerSettings.allowedAutorotateToLandscapeLeft)
                        {
                            if (PlayerSettings.allowedAutorotateToLandscapeRight)
                            {
                                CopyLandscapeRIPhoneSplash(editorTrampolineFolder, installPath);
                            }
                            else if (PlayerSettings.allowedAutorotateToPortrait)
                            {
                                CopyPortraitIPhoneSplash(editorTrampolineFolder, installPath);
                            }
                            else if (PlayerSettings.allowedAutorotateToPortraitUpsideDown)
                            {
                                CopyPortraitUIPhoneSplash(editorTrampolineFolder, installPath);
                            }
                            break;
                        }
                        CopyLandscapeLIPhoneSplash(editorTrampolineFolder, installPath);
                        break;
                }
                File.SetLastWriteTime(dst, DateTime.Now);
            }
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-Portrait.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-PortraitU.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-LandscapeL.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-LandscapeR.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-Portrait@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-PortraitU@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-LandscapeL@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-LandscapeR@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-Portrait-568h@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-Portrait-568h-U@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-Landscape-568h-L@2x.png");
            FileUtil.DeleteFileOrDirectory(installPath + "/SplashScreen-Landscape-568h-R@2x.png");
            FileUtil.MoveFileIfExists(stagingArea + "/Icon.png", installPath + "/Icon.png");
            FileUtil.MoveFileIfExists(stagingArea + "/Icon@2x.png", installPath + "/Icon@2x.png");
        }

        private static void InstalliPhonePluginFiles(string source, string destination, string reservedDestination, bool symlink)
        {
            if (Directory.Exists(source))
            {
                foreach (string str in Directory.GetFiles(source))
                {
                    string path = Path.Combine(!isReservedFile(str) ? destination : reservedDestination, Path.GetFileName(str));
                    FileUtil.DeleteFileOrDirectory(path);
                    if (symlink)
                    {
                        SymlinkFile(Path.GetFullPath(str), path);
                    }
                    else
                    {
                        FileUtil.ReplaceFile(Path.GetFullPath(str), path);
                    }
                }
            }
        }

        private static void InstallXcode4Plugin()
        {
            string path = Path.Combine(BuildPipeline.GetBuildToolsDirectory(BuildTarget.iPhone), "Unity4XC.xcplugin");
            bool flag = Directory.Exists(kXcodePluginDestination);
            if (flag && (string.Compare(Path.GetFullPath(Unsupported.ResolveSymlinks(kXcodePluginDestination)), Path.GetFullPath(path), StringComparison.InvariantCultureIgnoreCase) != 0))
            {
                Xcode4Controller.Log("Plugin points to wrong location. Removing.", new object[0]);
                Directory.Delete(kXcodePluginDestination);
                flag = false;
            }
            if (!flag)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(kXcodePluginDestination));
                CreateDirectory(dirInfo);
                SymlinkFile(path, kXcodePluginDestination);
                Unsupported.TerminateIPhoneXCode4();
            }
        }

        private static bool IsIPadEnabled()
        {
            return (PlayerSettings.iOS.targetDevice != iOSTargetDevice.iPhoneOnly);
        }

        private static bool IsIPhoneEnabled()
        {
            return (PlayerSettings.iOS.targetDevice != iOSTargetDevice.iPadOnly);
        }

        private static bool IsiPhonePluginFile(string fileName)
        {
            return (((fileName != null) && !Path.GetFileName(fileName).StartsWith(".")) && ((((fileName.EndsWith(".a") || fileName.EndsWith(".m")) || (fileName.EndsWith(".mm") || fileName.EndsWith(".cpp"))) || (fileName.EndsWith(".c") || fileName.EndsWith(".xib"))) || fileName.EndsWith(".png")));
        }

        private static bool isReservedFile(string fileName)
        {
            <isReservedFile>c__AnonStorey32 storey = new <isReservedFile>c__AnonStorey32 {
                fNameOnly = Path.GetFileName(fileName)
            };
            return Array.Exists<string>(kReservedFilenames, new Predicate<string>(storey.<>m__4B));
        }

        private static bool IsSimulatorSDK(string sdkVersion)
        {
            return ((sdkVersion != null) && sdkVersion.StartsWith("iphonesimulator"));
        }

        internal static bool IsValidBundleIdentifier(string domainish, string extraValidChars)
        {
            if (string.IsNullOrEmpty(domainish))
            {
                return false;
            }
            if (domainish == "com.Company.ProductName")
            {
                return false;
            }
            string str = "a-zA-Z0-9" + extraValidChars;
            Regex regex = new Regex(string.Format("^([{0}]+[.])*[{0}]+[.][{0}]+$", str));
            return regex.IsMatch(domainish);
        }

        public static void Launch(BuildTarget target, string path)
        {
            if (useXcode4)
            {
                LaunchInXcode4(target, path);
            }
            else
            {
                LaunchInXcode3(target, path);
            }
        }

        public static void LaunchAndWaitForXcode4()
        {
            if (!XcodeIsRunning() || !Xcode4Controller.WaitForPluginStartup(10))
            {
                Xcode4Controller.Log("Terminating Xcode if running", new object[0]);
                Unsupported.TerminateIPhoneXCode4();
                Xcode4Controller.Log("Launching Xcode", new object[0]);
                Unsupported.LaunchIPhoneXCode4();
                Xcode4Controller.WaitForPluginStartup(30);
            }
        }

        public static void LaunchInXcode3(BuildTarget target, string path)
        {
            if (!File.Exists("/usr/bin/osascript"))
            {
                throw new System.Exception("Please make sure apple script is installed. Otherwise Unity can not complete the build and run process.");
            }
            if (!Unsupported.CheckIPhoneXCodeInstalled())
            {
                throw new System.Exception("Please make sure Xcode 3.1 including the iPhone SDK is installed.");
            }
            string str = Path.Combine(path, "Unity-iPhone.xcodeproj");
            EditorUtility.DisplayProgressBar("Building Player", "Build & Install iPhone player", 1f);
            List<string> list = new List<string>();
            list.Clear();
            list.Add("tell application \"Xcode\"");
            list.Add("close (every window whose name contains \"Unity-iPhone\")");
            list.Add("open \"" + str + "\"");
            list.Add("tell project\"Unity-iPhone\"");
            list.Add("repeat while (currently building) = true");
            list.Add("end repeat");
            list.Add("set the active target to the target named \"Unity-iPhone\"");
            list.Add("set the active executable to the executable named \"Unity-iPhone\"");
            list.Add("clean");
            list.Add("build using \"Debug\"");
            list.Add("debug");
            list.Add("end tell");
            list.Add("end tell");
            LaunchOsascript(list.ToArray(), false);
        }

        public static void LaunchInXcode4(BuildTarget target, string path)
        {
            try
            {
                LaunchAndWaitForXcode4();
                CloseUnityProjectsInXcode4();
                string str = Path.Combine(path, "Unity-iPhone.xcodeproj");
                EditorUtility.DisplayProgressBar("Building Player", "Build & Install iPhone player", 1f);
                Xcode4Controller.OpenProject(str);
                string sdkVersion = ResolveiOSSDKVersion((int) PlayerSettings.iOS.sdkVersion);
                if (!IsSimulatorSDK(sdkVersion))
                {
                    Xcode4Controller.SelectDeviceScheme();
                }
                else
                {
                    Xcode4Controller.SelectSimulatorScheme(string.Format("{0} Simulator", GetSDKNumber(sdkVersion)));
                }
                Xcode4Controller.CleanProject();
                Xcode4Controller.RunProject();
            }
            catch (System.Exception exception)
            {
                object[] param = new object[] { exception };
                Xcode4Controller.Log("{0}", param);
                throw new UnityException("Launching iOS project via Xcode4 failed. Check editor log for details.");
            }
        }

        public static void LaunchOsascript(string[] script, bool wait)
        {
            string tempFileName = Path.GetTempFileName();
            File.WriteAllLines(tempFileName, script);
            Process process = new Process {
                StartInfo = { FileName = "/usr/bin/osascript", Arguments = tempFileName }
            };
            process.Start();
            if (wait)
            {
                process.WaitForExit();
            }
            process.Dispose();
        }

        private static bool MatchesAny(string dst, Regex[] ignoreList)
        {
            <MatchesAny>c__AnonStorey31 storey = new <MatchesAny>c__AnonStorey31 {
                dst = dst
            };
            return Array.Exists<Regex>(ignoreList, new Predicate<Regex>(storey.<>m__4A));
        }

        private static void MoveDirectoryRecursive(string source, string target, bool overwrite)
        {
            FileUtil.CopyDirectoryRecursive(source, target, overwrite);
            FileUtil.DeleteFileOrDirectory(source);
        }

        internal static void PostProcess(BuildTarget target, string stagingAreaData, string stagingArea, string stagingAreaDataManaged, string playerPackage, string installPath, string companyName, string productName, BuildOptions options, RuntimeClassRegistry usedClassRegistry)
        {
            string from = stagingAreaData;
            bool flag = false;
            bool advancedLicense = PlayerSettings.advancedLicense;
            string sdkVersion = ResolveiOSSDKVersion((int) PlayerSettings.iOS.sdkVersion);
            string targetOS = ResolveiOSSDKVersion((int) PlayerSettings.iOS.targetOSVersion);
            bool appendMode = (options & BuildOptions.AcceptExternalModificationsToPlayer) != BuildOptions.None;
            if (((PlayerSettings.strippingLevel >= StrippingLevel.StripByteCode) && !IsSimulatorSDK(sdkVersion)) && (((options & BuildOptions.AllowDebugging) == BuildOptions.None) || ((options & BuildOptions.Development) == BuildOptions.None)))
            {
                flag = true;
            }
            CrossCompileOptions @static = CrossCompileOptions.Static;
            if (PlayerSettings.iOS.scriptCallOptimization >= ScriptCallOptimizationLevel.FastButNoExceptions)
            {
                @static |= CrossCompileOptions.FastICall;
            }
            if (((options & BuildOptions.AllowDebugging) != BuildOptions.None) && ((options & BuildOptions.Development) != BuildOptions.None))
            {
                @static |= CrossCompileOptions.Debugging;
            }
            if ((((options & BuildOptions.Development) != BuildOptions.None) && !advancedLicense) || (((options & BuildOptions.AllowDebugging) != BuildOptions.None) && ((options & BuildOptions.Development) != BuildOptions.None)))
            {
                @static |= CrossCompileOptions.ExplicitNullChecks;
            }
            string bundleIdentifier = PlayerSettings.bundleIdentifier;
            if (!IsValidBundleIdentifier(bundleIdentifier, "-"))
            {
                string message = "Please set up the iPhoneBundleIdentifier in the Player Settings.";
                message = (message + " The value must follow the convention 'com.YourCompanyName.YourProductName'" + " and can contain alphanumeric characters.") + " You also have to create a Provisioning Profile with the same identifier" + " and install it in the Xcode Organizer Provisioning Profiles.";
                EditorUtility.DisplayDialog("iPhoneBundleIdentifier has not been set up correctly", message, "Ok");
                Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
                throw new System.Exception("iPhoneBundleIdentifier has not been set up.\n" + message);
            }
            string str6 = bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1);
            string iPhoneCompanyName = bundleIdentifier.Substring(0, bundleIdentifier.LastIndexOf("."));
            string dst = stagingArea + "/iPhone-Trampoline";
            string src = Path.Combine(playerPackage, "iPhone-Trampoline");
            Regex[] ignoreList = new Regex[] { new Regex("libiPhone-lib.*") };
            CopyRecursiveWithIgnoreList(src, dst, ignoreList);
            if (!appendMode)
            {
                string environmentVariable = Environment.GetEnvironmentVariable("USER");
                if (!"user".Equals(environmentVariable))
                {
                    string str11 = Path.Combine(dst, "Unity-iPhone.xcodeproj");
                    try
                    {
                        if (!File.Exists(Path.Combine(str11, environmentVariable + ".pbxuser")))
                        {
                            File.Move(Path.Combine(str11, "user.pbxuser"), Path.Combine(str11, environmentVariable + ".pbxuser"));
                        }
                    }
                    catch (System.Exception exception)
                    {
                        UnityEngine.Debug.LogError(exception);
                    }
                }
            }
            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
            bool withMethods = false;
            bool ignoreSystemDlls = false;
            checker.CollectReferences(stagingAreaDataManaged, withMethods, 0f, ignoreSystemDlls);
            if (!advancedLicense)
            {
                string str12 = checker.WhoReferencesClass("System.Net.Sockets", true);
                if (str12 != null)
                {
                    throw new SystemException("System.Net.Sockets are supported only on Unity iOS Pro. Referenced from assembly '" + str12 + "'.");
                }
            }
            FileUtil.CopyFileOrDirectory(dst + "/Data/unity default resources", from + "/unity default resources");
            FileUtil.CopyFileOrDirectory(dst + "/Data/mono", from + "/Managed/mono");
            string targetCrossCompiledASMFolder = Path.Combine(dst, "Libraries");
            if (!MonoCrossCompile.CrossCompileAOTDirectoryParallel(target, @static, stagingAreaDataManaged, targetCrossCompiledASMFolder, PlayerSettings.aotOptions))
            {
                throw new UnityException("Cross compilation failed.");
            }
            MonoAOTRegistration.WriteCPlusPlusFileForStaticAOTModuleRegistration(target, targetCrossCompiledASMFolder, @static, advancedLicense, ((int) PlayerSettings.iOS.targetDevice).ToString(), (PlayerSettings.strippingLevel > StrippingLevel.Disabled) && !IsSimulatorSDK(sdkVersion), usedClassRegistry, checker);
            string path = Path.Combine(dst, "Unity-iPhone.xcodeproj/project.pbxproj");
            string xcodeUserProjectFile = GetXcodeUserProjectFile();
            string str17 = Path.Combine(dst, xcodeUserProjectFile);
            if (appendMode && File.Exists(installPath + "/Unity-iPhone.xcodeproj/project.pbxproj"))
            {
                FileUtil.DeleteFileOrDirectory(path);
                FileUtil.CopyFileOrDirectory(installPath + "/Unity-iPhone.xcodeproj/project.pbxproj", path);
            }
            if (appendMode && File.Exists(Path.Combine(installPath, xcodeUserProjectFile)))
            {
                FileUtil.DeleteFileOrDirectory(str17);
                FileUtil.CopyFileOrDirectory(Path.Combine(installPath, xcodeUserProjectFile), str17);
            }
            List<string> includedFiles = new List<string>();
            AddiPhoneAssemblyFiles(includedFiles, checker.GetAssemblyFileNames());
            AddiPhonePluginFiles(includedFiles);
            AddStandardImages(includedFiles);
            BuildXCodeProject(path, includedFiles, sdkVersion, targetOS, appendMode);
            string[] input = new string[] { "Unity-Target-New", str6 };
            FileUtil.ReplaceText(path, input);
            if (sdkVersion.Length > 0)
            {
                string[] textArray2 = new string[] { "activeSDKPreference = .*;", "activeSDKPreference = " + sdkVersion + ";" };
                if (!FileUtil.ReplaceTextRegex(str17, textArray2))
                {
                    FileUtil.AppendTextAfter(str17, "activeExecutable = ", "activeSDKPreference = " + sdkVersion + ";");
                }
                string[] textArray3 = new string[] { "activeTarget = .*;", "activeTarget = 1D6058900D05DD3D006BFB54 /* Unity-iPhone */;" };
                FileUtil.ReplaceTextRegex(str17, textArray3);
                string[] textArray4 = new string[] { "activeExecutable = .*;", "activeExecutable = 567678E6115A681D00007F8E /* Unity-iPhone */;" };
                FileUtil.ReplaceTextRegex(str17, textArray4);
            }
            if (Directory.Exists("Assets/StreamingAssets"))
            {
                FileUtil.CopyDirectoryRecursiveForPostprocess("Assets/StreamingAssets", from + "/Raw", true);
            }
            string filename = Path.Combine(dst, "Info.plist");
            UpdateInfoPlist(stagingArea, filename, iPhoneCompanyName);
            if (flag)
            {
                EditorUtility.DisplayProgressBar("Stripping bytecode from assemblies", "Stripping bytecode from assemblies", 0.95f);
                MonoAssemblyStripping.MonoCilStrip(target, stagingAreaDataManaged, checker.GetAssemblyFileNames());
            }
            FileUtil.DeleteFileOrDirectory(dst + "/Data");
            FileUtil.MoveFileOrDirectory(from, dst + "/Data");
            if ((options & BuildOptions.InstallInBuildFolder) != BuildOptions.None)
            {
                string str19 = playerPackage + "/DebugPlayer/Data";
                FileUtil.DeleteFileOrDirectory(str19);
                FileUtil.MoveFileOrDirectory(dst + "/Data", str19);
                string str20 = playerPackage + "/DebugPlayer/Libraries";
                FileUtil.DeleteFileOrDirectory(str20);
                FileUtil.MoveFileOrDirectory(dst + "/Libraries", str20);
            }
            else
            {
                UpdateInstallLocation(src, dst, stagingArea, installPath, options, appendMode, sdkVersion);
                if (PlayerSettings.iOS.targetOSVersion < iOSTargetOSVersion.iOS_4_3)
                {
                    UnityEngine.Debug.LogWarning("If this application was previously submitted to the App Store as ARMv6+ARMv7 or ARMv6-only application then Target iOS Version Player Setting should be set to \"4.3\" or higher when releasing new update.");
                }
            }
        }

        private static bool ReplaceMultilinePropertyIfMatch(IEnumerator it, string propname, string newValue, ArrayList xcodeXMLFileContentOut)
        {
            string current = (string) it.Current;
            if (current.IndexOf(propname + " = ") == -1)
            {
                return false;
            }
            while (!((string) it.Current).Contains(";"))
            {
                if (!it.MoveNext())
                {
                    break;
                }
            }
            if (newValue.Contains("\n"))
            {
                xcodeXMLFileContentOut.Add(string.Format("\t\t\t\t{0} = (", propname));
                xcodeXMLFileContentOut.Add(newValue);
                xcodeXMLFileContentOut.Add("\t\t\t\t);");
            }
            else
            {
                xcodeXMLFileContentOut.Add(string.Format("\t\t\t\t{0} = {1};", propname, newValue));
            }
            return true;
        }

        private static bool ReplacePropertyLineIfMatch(string sourceLine, string propname, string newValue, ArrayList xcodeXMLFileContentOut)
        {
            int index = sourceLine.IndexOf(propname + " = ");
            if (index == -1)
            {
                return false;
            }
            int num2 = sourceLine.IndexOf(";");
            if (num2 == -1)
            {
                xcodeXMLFileContentOut.Add(sourceLine);
            }
            else
            {
                xcodeXMLFileContentOut.Add(sourceLine.Replace(sourceLine.Substring(index, (num2 - index) + 1), propname + " = " + newValue + ";"));
            }
            return true;
        }

        private static string ResolveiOSSDKVersion(int key)
        {
            if (key < kiOSSDKVersions.Length)
            {
                return kiOSSDKVersions[key];
            }
            if (key == 0x3dc)
            {
                return "iphoneos";
            }
            if (key == 0x3dd)
            {
                return "iphonesimulator";
            }
            return string.Empty;
        }

        private static string ResolveXcodeFiletypeFromName(string fileName)
        {
            if (fileName.EndsWith(".cpp"))
            {
                return "sourcecode.cpp.cpp";
            }
            if (fileName.EndsWith(".c"))
            {
                return "sourcecode.c.c";
            }
            if (fileName.EndsWith(".m"))
            {
                return "sourcecode.c.objc";
            }
            if (fileName.EndsWith(".mm"))
            {
                return "sourcecode.cpp.objcpp";
            }
            if (fileName.EndsWith(".a"))
            {
                return "archive.ar";
            }
            if (fileName.EndsWith(".xib"))
            {
                return "file.xib";
            }
            if (fileName.EndsWith(".png"))
            {
                return "image.png";
            }
            return "sourcecode.asm";
        }

        private static void SymlinkFile(string src, string dst)
        {
            if (File.Exists(dst))
            {
                File.Delete(dst);
            }
            string[] textArray1 = new string[] { "-s '", Path.GetFullPath(src), "' '", Path.GetFullPath(dst), "'" };
            ProcessStartInfo info = new ProcessStartInfo("ln", string.Concat(textArray1));
            using (Process process = new Process())
            {
                process.StartInfo = info;
                process.Start();
                process.WaitForExit();
                if (process.ExitCode != 0)
                {
                    UnityEngine.Debug.LogWarning("Failed symlinking runtime library. Falling back to copy.");
                    FileUtil.CopyFileOrDirectory(src, dst);
                }
            }
        }

        private static void UpdateInfoPlist(string stagingArea, string filename, string iPhoneCompanyName)
        {
            string[] input = new string[] { "com.unity3d", iPhoneCompanyName };
            FileUtil.ReplaceText(filename, input);
            ArrayList list = FileUtil.ReadAllText(filename);
            ArrayList strings = new ArrayList();
            for (int i = 0; i < list.Count; i++)
            {
                string str = (string) list[i];
                if (str.IndexOf("</dict>") >= 0)
                {
                    strings.Add("\t<key>CFBundleVersion</key>");
                    strings.Add("\t<string>" + PlayerSettings.bundleVersion + "</string>");
                    strings.Add("\t<key>CFBundleDisplayName</key>");
                    if ((PlayerSettings.iOS.applicationDisplayName != null) && (PlayerSettings.iOS.applicationDisplayName.Length > 0))
                    {
                        strings.Add("\t<string>" + PlayerSettings.iOS.applicationDisplayName + "</string>");
                    }
                    else
                    {
                        strings.Add("\t<string>${PRODUCT_NAME}</string>");
                    }
                    if (IsIPadEnabled() && IsIPhoneEnabled())
                    {
                        strings.Add("\t<key>CFBundleIconFiles</key>");
                        strings.Add("\t<array>");
                        strings.Add("\t\t<string>Icon.png</string>");
                        strings.Add("\t\t<string>Icon-72.png</string>");
                        strings.Add("\t\t<string>Icon-144.png</string>");
                        strings.Add("\t\t<string>Icon@2x.png</string>");
                        strings.Add("\t</array>");
                    }
                    else
                    {
                        strings.Add("\t<key>CFBundleIconFiles</key>");
                        strings.Add("\t<array>");
                        strings.Add("\t\t<string>Icon.png</string>");
                        strings.Add("\t\t<string>Icon@2x.png</string>");
                        strings.Add("\t</array>");
                    }
                    bool flag = PlayerSettings.defaultInterfaceOrientation == UIOrientation.AutoRotation;
                    strings.Add("\t<key>UISupportedInterfaceOrientations</key>");
                    strings.Add("\t<array>");
                    if ((PlayerSettings.defaultInterfaceOrientation == UIOrientation.Portrait) || (flag && PlayerSettings.allowedAutorotateToPortrait))
                    {
                        strings.Add("\t\t<string>UIInterfaceOrientationPortrait</string>");
                    }
                    if ((PlayerSettings.defaultInterfaceOrientation == UIOrientation.PortraitUpsideDown) || (flag && PlayerSettings.allowedAutorotateToPortraitUpsideDown))
                    {
                        strings.Add("\t\t<string>UIInterfaceOrientationPortraitUpsideDown</string>");
                    }
                    if ((PlayerSettings.defaultInterfaceOrientation == UIOrientation.LandscapeLeft) || (flag && PlayerSettings.allowedAutorotateToLandscapeLeft))
                    {
                        strings.Add("\t\t<string>UIInterfaceOrientationLandscapeRight</string>");
                    }
                    if ((PlayerSettings.defaultInterfaceOrientation == UIOrientation.LandscapeRight) || (flag && PlayerSettings.allowedAutorotateToLandscapeRight))
                    {
                        strings.Add("\t\t<string>UIInterfaceOrientationLandscapeLeft</string>");
                    }
                    strings.Add("\t</array>");
                    strings.Add("\t<key>UIInterfaceOrientation</key>");
                    switch (PlayerSettings.defaultInterfaceOrientation)
                    {
                        case UIOrientation.Portrait:
                            strings.Add("\t<string>UIInterfaceOrientationPortrait</string>");
                            break;

                        case UIOrientation.PortraitUpsideDown:
                            strings.Add("\t<string>UIInterfaceOrientationPortraitUpsideDown</string>");
                            break;

                        case UIOrientation.LandscapeRight:
                            strings.Add("\t<string>UIInterfaceOrientationLandscapeLeft</string>");
                            break;

                        case UIOrientation.LandscapeLeft:
                            strings.Add("\t<string>UIInterfaceOrientationLandscapeRight</string>");
                            break;

                        default:
                            strings.Add("\t<string></string>");
                            break;
                    }
                    strings.Add("\t<key>UIPrerenderedIcon</key>");
                    strings.Add(!PlayerSettings.iOS.prerenderedIcon ? "\t<false/>" : "\t<true/>");
                    strings.Add("\t<key>UIRequiresPersistentWiFi</key>");
                    strings.Add(!PlayerSettings.iOS.requiresPersistentWiFi ? "\t<false/>" : "\t<true/>");
                    strings.Add("\t<key>UIStatusBarHidden</key>");
                    strings.Add(!PlayerSettings.statusBarHidden ? "\t<false/>" : "\t<true/>");
                    strings.Add("\t<key>UIStatusBarStyle</key>");
                    switch (PlayerSettings.iOS.statusBarStyle)
                    {
                        case iOSStatusBarStyle.Default:
                            strings.Add("\t<string>UIStatusBarStyleDefault</string>");
                            break;

                        case iOSStatusBarStyle.BlackTranslucent:
                            strings.Add("\t<string>UIStatusBarStyleBlackTranslucent</string>");
                            break;

                        case iOSStatusBarStyle.BlackOpaque:
                            strings.Add("\t<string>UIStatusBarStyleBlackOpaque</string>");
                            break;

                        default:
                            strings.Add("\t<string></string>");
                            break;
                    }
                    strings.Add("\t<key>UIApplicationExitsOnSuspend</key>");
                    strings.Add(!PlayerSettings.iOS.exitOnSuspend ? "\t<false/>" : "\t<true/>");
                    strings.Add("\t<key>UIRequiredDeviceCapabilities</key>");
                    strings.Add("\t<array><string>armv7</string></array>");
                }
                strings.Add(str);
            }
            FileUtil.WriteAllText(filename, strings);
        }

        private static void UpdateInstallLocation(string editorTrampolineFolder, string tempData, string stagingArea, string installPath, BuildOptions options, bool appendMode, string sdkVersion)
        {
            if (useXcode4)
            {
                InstallXcode4Plugin();
            }
            string str = Path.Combine(installPath, "Libraries");
            string reservedDestination = Path.Combine(installPath, "Classes");
            string src = Path.Combine(editorTrampolineFolder, "Libraries/libiPhone-lib.a");
            string dst = Path.Combine(str, "libiPhone-lib.a");
            if (IsSimulatorSDK(sdkVersion))
            {
                src = Path.Combine(editorTrampolineFolder, "Libraries/libiPhone-lib-i386.a");
            }
            else if ((options & BuildOptions.Development) != BuildOptions.None)
            {
                src = Path.Combine(editorTrampolineFolder, "Libraries/libiPhone-lib-dev.a");
            }
            if ((options & BuildOptions.AutoRunPlayer) != BuildOptions.None)
            {
                EditorUtility.DisplayProgressBar("Closing open Unity projects in Xcode", "Closing open Unity projects in Xcode", 0.97f);
                CloseUnityProjectsInXcode();
            }
            if (!appendMode)
            {
                FileUtil.DeleteFileOrDirectory(installPath);
                FileUtil.MoveFileOrDirectory(tempData, installPath);
            }
            else
            {
                FileUtil.DeleteFileOrDirectory(installPath + "/Unity-iPhone.xcodeproj/project.pbxproj");
                FileUtil.CopyFileOrDirectory(tempData + "/Unity-iPhone.xcodeproj/project.pbxproj", installPath + "/Unity-iPhone.xcodeproj/project.pbxproj");
                FileUtil.DeleteFileOrDirectory(Path.Combine(installPath, GetXcodeUserProjectFile()));
                FileUtil.CopyFileOrDirectory(Path.Combine(tempData, GetXcodeUserProjectFile()), Path.Combine(installPath, GetXcodeUserProjectFile()));
                DeleteNonHiddenFilesOrDirectories(installPath + "/Data");
                MoveDirectoryRecursive(tempData + "/Data", installPath + "/Data", true);
                DeleteNonHiddenFilesOrDirectories(str);
                MoveDirectoryRecursive(tempData + "/Libraries", str, true);
                FileUtil.DeleteFileOrDirectory(installPath + "/Info.plist");
                FileUtil.MoveFileOrDirectory(tempData + "/Info.plist", installPath + "/Info.plist");
                FileUtil.DeleteFileOrDirectory(tempData);
            }
            bool symlink = (options & BuildOptions.SymlinkLibraries) != BuildOptions.None;
            if (symlink)
            {
                SymlinkFile(src, dst);
            }
            else
            {
                FileUtil.ReplaceFile(src, dst);
            }
            InstalliPhonePluginFiles("Assets/Plugins/iOS", str, reservedDestination, symlink);
            InstalliPhoneIcons(editorTrampolineFolder, tempData, stagingArea, installPath, appendMode);
            if (IsIPadEnabled())
            {
                InstalliPadIcons(editorTrampolineFolder, tempData, stagingArea, installPath, appendMode);
            }
        }

        private static bool UpdateMultilinePropertyIfMatch(IEnumerator it, string propname, string[] addValues, string[] removeValues, ArrayList xcodeXMLFileContentOut)
        {
            string current = (string) it.Current;
            if (current.IndexOf(propname + " = ") == -1)
            {
                return false;
            }
            HashSet<string> source = new HashSet<string>();
            while (!((string) it.Current).Contains(";"))
            {
                if (!it.MoveNext() || ((string) it.Current).Contains(";"))
                {
                    break;
                }
                source.Add(ExtractValue((string) it.Current));
            }
            source.ExceptWith(removeValues);
            source.UnionWith(addValues);
            if (source.Count > 1)
            {
                xcodeXMLFileContentOut.Add(string.Format("\t\t\t\t{0} = (", propname));
                foreach (string str2 in source)
                {
                    xcodeXMLFileContentOut.Add(string.Format("\t\t\t\t\"{0}\",", str2));
                }
                xcodeXMLFileContentOut.Add("\t\t\t\t);");
            }
            else
            {
                xcodeXMLFileContentOut.Add(string.Format("\t\t\t\t{0} = \"{1}\";", propname, source.ToArray<string>()[0]));
            }
            return true;
        }

        private static bool XcodeIsRunning()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("/bin/ps") {
                Arguments = "axc -o pid,state,command",
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };
            Process process = Process.Start(startInfo);
            process.WaitForExit(0x2710);
            char[] separator = new char[] { '\n' };
            foreach (string str2 in process.StandardOutput.ReadToEnd().Split(separator))
            {
                Match match = Regex.Match(str2, @"(\d+) (....) (.*)$");
                if (match.Success)
                {
                    string str3 = match.Groups[2].ToString();
                    if (((str3[0] != 'T') && (str3[0] != 'Z')) && (!str3.Contains("E") && match.Groups[3].ToString().Contains("Xcode")))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        private static bool useXcode4
        {
            get
            {
                return (EditorPrefs.GetBool("Xcode4Support", true) && Unsupported.CheckIPhoneXCode4Installed());
            }
        }

        [CompilerGenerated]
        private sealed class <isReservedFile>c__AnonStorey32
        {
            internal string fNameOnly;

            internal bool <>m__4B(string element)
            {
                return (string.Compare(element, this.fNameOnly, true) == 0);
            }
        }

        [CompilerGenerated]
        private sealed class <MatchesAny>c__AnonStorey31
        {
            internal string dst;

            internal bool <>m__4A(Regex val)
            {
                return val.IsMatch(this.dst);
            }
        }
    }
}

